//
// Created by jsjxsy on 2022/7/6.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct apple {
  int weight;
  int color;
};

struct apple *get_apple_info() {
  struct apple *a1;
  a1 = malloc(sizeof(struct apple));
  if (a1 == NULL) {
    printf("malloc error.\n");
    return NULL;
  }

  a1->weight = 2;
  a1->color = 1;

  return a1;
}

typedef struct apple Apple;
int main(int argc, char *argv[]) {
  //定义一个变量r1,用于接收函数get_apple_info()返回的值，
  // 由于该函数返回的类型是：struct apple *，
  // 所以变量r1也是该类型。注意，函数不会执行。
  typeof(get_apple_info()) r1;

  r1 = get_apple_info();

  printf("apple weight:%d\n", r1->weight);
  printf("apple color:%d\n", r1->color);
  free(r1);

  Apple *r2;
  r2 = get_apple_info();
  r2->weight = 19;
  r2->color = 2;
  printf("apple weight:%d\n", r2->weight);
  printf("apple color:%d\n", r2->color);
  free(r2);
  return 0;
}

